package rule17;

/**
 * @author ChangLiang
 * @date 2020/3/17
 */
public final class Complex {

    private final int a;

    private final int b;

    private Complex(int a, int b) {
        this.a = a;
        this.b = b;
    }

    /**
     * valueof method：static factory method
     * @param a
     * @param b
     * @return
     */
    public static Complex valueOf(int a, int b) {
        return new Complex(a, b);
    }

    public Complex add(Complex c) {
        return new Complex(this.a + c.a, this.b + c.b);
    }

    public Complex subtract(Complex c) {
        return new Complex(this.a - c.a, this.b - c.b);
    }
}
